package com.xuxiangyang.competitionsystem.tools;

import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;
import com.deepoove.poi.data.TextRenderData;
import com.deepoove.poi.policy.ListRenderPolicy;
import lombok.extern.slf4j.Slf4j;
//import org.hzero.core.util.UUIDUtils;
//import org.srm.demo.infra.constant.Constants;

import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author Lijx
 * @Date 2021/7/26
 */
@Slf4j
public final class WordUtils {

    public static void main(String[] args) throws IOException{

        Map<String, Object> data = new HashMap<>();
        InputStream inputStream = Thread.currentThread().getContextClassLoader()
                .getResourceAsStream("src/main/resources/templates/template.docx");
        ListRenderPolicy policy = new ListRenderPolicy();
        Configure config = Configure.newBuilder()
                .bind("name", policy).build();

        ArrayList<Object> list = new ArrayList<Object>();
        list.add(new TextRenderData("司天宏123"));
        list.add(new TextRenderData("司天宏321"));

        data.put("name", list);
        data.put("start_time", "2020-09-17");

        XWPFTemplate template = XWPFTemplate.compile("src/main/resources/templates/template.docx",config)
                .render(data);
        FileOutputStream out;
        out = new FileOutputStream("D:/Desktop/template2.docx");
        template.write(out);
        out.flush();
        out.close();
        template.close();
    }

}
